/*
 * Copyright 2007. Mount Sinai Hospital, Toronto, Canada.
 * 
 * Licensed under the GNU Lesser General Public License, Version 2. You
 * can find a copy of the license at:
 * 
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 * 
 * IN NO EVENT SHALL MOUNT SINAI HOSPITAL BE LIABLE TO ANY PARTY FOR DIRECT, 
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST 
 * PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, 
 * EVEN IF MOUNT SINAI HOSPITAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
 * DAMAGE.
 * 
 * MOUNT SINAI HOSPITAL SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND 
 * ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". 
 * MOUNT SINAI HOSPITAL HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
 */
package com.sinai.mshab.client.ui.basic;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.sinai.mshab.client.ui.FormComponent;
import com.sinai.mshab.client.ui.aggregate.DataReceiver;

/**
 * The only purpose of this button is to notify the panel that contains it.
 * @author serge
 */
public abstract class NotifierButton extends BasicFormComponent {
	
	protected String message;
	private Button b;
	
	/**
	 * Creates a new notifier button with a message
	 * like "Another Instance of?"
	 * @param message the message for the button to display
	 */
	public NotifierButton(String message) {
		this.message =message;
		b = new Button(message);
		b.addClickListener(new MyListener());
		b.setStyleName("button");
		initWidget(b);
	}
	
	public abstract Object clone();
	
	/**
	 * Informs observers of change to this widget.
	 */
	private class MyListener implements ClickListener {
		public void onClick(Widget sender) {
				System.out.println("Another button got clicked.");
				notifyObservers(NotifierButton.this);
		}
	}

	public void sendAnswer(DataReceiver receiver) {
		
	}

	/**
	 * Since we wouldn't want <code>NotifierButton</code> appearing in a printable page,
	 * our toPrint returns an empty {@link HorizontalPanel}.  
	 */
	public HorizontalPanel toReport() {

		return new HorizontalPanel();
	}

	/**
	 * Doesn't really have a value, so false is always returned.
	 * 
	 * @see FormComponent#isEmpty()
	 */
	public boolean isEmpty() {
		return false;
	}

}
